<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ page import="java.util.List" %>
<%@ page import="com.pojo.basic.CUST" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ include file="/default.jsp"  %>

<%
	String root = (String)request.getAttribute("root");
%>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>GTC Content System</title>
<link rel="stylesheet" href="/Sunlike/extjs/resources/css/ext-all.css" type="text/css"></link>
<link rel="stylesheet" href="/Sunlike/css/toolbar.css" type="text/css"></link>
<script type="text/javascript" src="/Sunlike/extjs/adapter/ext/ext-base-debug.js"></script>
<script type="text/javascript" src="/Sunlike/extjs/ext-all-debug.js"></script>
<style type="text/css">
<!--
a{text-decoration:none;color:black;};
-->
</style>
<script type="text/javascript">
function panel()
{
	new Ext.Panel({
		renderTo:'paneldiv',
		autoHeight : true,
		frame : false,
		bodyStyle : "width:100%",
		autoWidth:true,
		tbar:[
			{text:'新增&nbsp;&nbsp;&nbsp;&nbsp;',iconCls:'user',listeners:{"click":add}},'-',
			{text:'編輯&nbsp;&nbsp;&nbsp;&nbsp;',iconCls:'edit'},'-',
			{text:'刪除&nbsp;&nbsp;&nbsp;&nbsp;',iconCls:'del'}
		],
		contentEl:'treediv'
	});	
}
Ext.onReady(panel);

function tree(){
	
	var treeLoader = new Ext.tree.TreeLoader({
		dataUrl : "moduleTypesAction.set.findChildModuleTypes.action"
	}); 
	
	treeLoader.on('beforeload',function(treeLoader, node) {
		treeLoader.baseParams = {
		    pid: ""+node.id,
	        date: new Date()
	    };
	}, this); 
	
	new Ext.tree.TreePanel({
		id:'tree',
		renderTo: 'treediv',
		animate:true,
		border:false,
		collapsible:false,
		rootVisible:false,
		autoScroll:false,
		autoHeight:true, 
		root: new Ext.tree.AsyncTreeNode({
			expanded: true,
			loader:treeLoader,
			children: [ <%= root %> ]
		}),
		listeners:{click:function(node,event){
	   		event.stopEvent(); 
	   		if (node.leaf==true) {  
	   		   	
	        }  
	   	}}
	});	  //new Ext.tree.TreePanel
} 
Ext.onReady(tree);

function add()
{
	var treepanel = Ext.getCmp("tree");
	var nodes = treepanel.getChecked(),pid;
	if(nodes.length==0){
		Ext.Msg.show({
			title:'系统提示！',
			msg: '請先勾選一個模組節點,未勾選默認為根節點！',
			fn:function(btn){
				if(btn == 'ok'){
					pid = -1;
				}else{
					pid = nodes[0].id;
				}
				var win = new Ext.Window({
					width:600,
					height:200,
					frame:true,
					title:"新增模組",
					closeAction : 'hide', 
					modal:true,
					buttons:[{text:"确定",handler:function(){
						var name   = Ext.get("moduleTypesVo.name").getValue(false).trim();
						var sort   = Ext.get("moduleTypesVo.sort").getValue(false).trim();
						var remark = Ext.get("moduleTypesVo.remark").getValue(false).trim();
						if(!name){
							Ext.Msg.show({
								title:'系统提示！',
								msg: '名稱不能為空！',
								buttons: Ext.Msg.OK,
								icon: Ext.MessageBox.INFO
							});
							return;
						}
						Ext.MessageBox.show({
						        msg: '正在保存數據，請稍等...',
						        progressText: 'Saving...',
						        width:300,
						        wait:true,
						        waitConfig: {interval:200},
						        icon:'ext-mb-download'
						 });
						Ext.Ajax.request({
							method:'POST',
					    	url:'moduleTypesAction.set.savaModuleTypes.action',
					    	params: {'moduleTypesVo.pid':pid,'moduleTypesVo.name':name,'moduleTypesVo.sort':sort,'moduleTypesVo.remark':remark},
					    	success:function(response){
					    		Ext.MessageBox.hide();
					    		Ext.MessageBox.show({
				    			 	title: '系統提示',
				    		        msg: '數據保存成功！',
				    		        width:300,
				    		        buttons: Ext.MessageBox.OK,
				    		        icon:Ext.MessageBox.INFO,
				    		        fn:function(){
				    		        	window.location.reload();
				    		        }
				    			});
					    	},
					    	failure:function(response){
					    		Ext.MessageBox.hide();
					    		Ext.MessageBox.alert('添加失敗！');
					    		 window.location.reload();
					    	}
						});
					}},{text:"取消",handler:function(){win.hide();}}],
					contentEl:'form'
				});
				Ext.get("form").setVisible(true);
				win.show();
			},
			buttons: Ext.Msg.OKCANCEL,
			icon: Ext.MessageBox.INFO
		});	
	}else{
		var win = new Ext.Window({
			width:600,
			height:200,
			frame:true,
			title:"新增模組",
			closeAction : 'hide', 
			modal:true,
			buttons:[{text:"确定",handler:function(){
				var name   = Ext.get("moduleTypesVo.name").getValue(false).trim();
				var sort   = Ext.get("moduleTypesVo.sort").getValue(false).trim();
				var remark = Ext.get("moduleTypesVo.remark").getValue(false).trim();
				if(!name){
					Ext.Msg.show({
						title:'系统提示！',
						msg: '名稱不能為空！',
						buttons: Ext.Msg.OK,
						icon: Ext.MessageBox.INFO
					});
					return;
				}
				Ext.MessageBox.show({
				        msg: '正在保存數據，請稍等...',
				        progressText: 'Saving...',
				        width:300,
				        wait:true,
				        waitConfig: {interval:200},
				        icon:'ext-mb-download'
				 });
				Ext.Ajax.request({
					method:'POST',
			    	url:'moduleTypesAction.set.savaModuleTypes.action',
			    	params: {'moduleTypesVo.pid':pid,'moduleTypesVo.name':name,'moduleTypesVo.sort':sort,'moduleTypesVo.remark':remark},
			    	success:function(response){
			    		Ext.msg.hide();
			    		Ext.msg.alert(response.info);
			    	},
			    	failure:function(response){
			    		Ext.msg.hide();
			    		Ext.msg.alert(response.info);
			    	}
				});
			}},{text:"取消",handler:function(){win.hide();}}],
			contentEl:'form'
		});
		Ext.get("form").setVisible(true);
		win.show();
	}
}

function sava()
{
}
</script>
</head>
<body>
<div id='toolbarspan'></div>

  
<div id="paneldiv" ></div>
<div id="treediv" ></div>
<div id="form" style="display:none;">
  <br>
  <table border="0" align="center" width="100%">
    <tr> 
      <td  width="100"> &nbsp;&nbsp;&nbsp;&nbsp; 
        <font color="black"><SPAN>名稱</SPAN></font>
      </td>
      <td> 
        <div align="left"> 
        	<SPAN><input id="moduleTypesVo.name" type="text" name="moduleTypesVo.name" size="55" value=""></SPAN>
        </div>
      </td>
    </tr>
    <tr> 
      <td  width="100">&nbsp;&nbsp;&nbsp;&nbsp; 
        <font color="black"><SPAN>排列順序</SPAN> </font>
      </td>
      <td> 
        <div align="left"> <SPAN>  
          <input id="moduleTypesVo.sort"  type="hidden" name="moduleTypesVo.sort" size="40" value="">
          </SPAN></div>
      </td>
    </tr>
    <tr> 
      <td  width="100">&nbsp;&nbsp;&nbsp;&nbsp; 
        <font color="black"><SPAN>描述</SPAN> </font>
      </td>
      <td> <SPAN> 
        <textarea id="moduleTypesVo.remark" name="moduleTypesVo.remark" rows="3" cols="55"></textarea>
        </SPAN></td>
    </tr>
  </table>
  <br>
</div>
</body>
</html>